<?php
namespace ZHMVC\DB\MANAGER;

if (! isset($_SESSION)) {
    session_start();
}
include (dirname(dirname(__FILE__)) . "/zhconfig/Config.php");
include (ZH_PATH . DS . MANAGERFPATH . DS . 'islogin' . ZH);

$isp = new \ZHMVC\D\MANAGER\isPermission();
$isper = $isp->getPermission();
$_curlid = $isp->getCUrl();
$c = new \ZHCONFIG\ZhConfig();
$db_pre = $c->getDbPre();

if ($isper == 1) {
    $ErrMsg = "对不起，你没有访问该页面的权限";
    echo $ErrMsg;
    exit();
} elseif ($isper == 0) {
    $ErrMsg = "对不起，地址错误";
    echo $ErrMsg;
    exit();
}

include (ZH_PATH . DS . MANAGERFPATH . DS . 'top1' . ZH);
?>
<script type="text/javascript"
	src="/common/hui/lib/jquery/1.9.1/jquery.min.js"></script>
<div class="wap-container">
	<nav class="breadcrumb" style="background-color: #fff; padding: 0 24px">
		管理员管理 <a class="btn btn-success radius f-r"
			style="line-height: 1.6em; margin-top: 3px"
			href="javascript:location.replace(location.href);" title="刷新"><i
			class="Hui-iconfont">&#xe68f;</i></a>
	</nav>
<?php
$action = SafeRequest(getPGC('atcion'), 0);
switch ($action) {
    case "save":
        save($db_pre);
        break;
    case "add":
        add($db_pre);
        break;
    case "del":
        del($db_pre);
        break;
    default:
        main($db_pre);
}

function main($db_pre)
{
    ?>
<article class="Hui-admin-content clearfix">
		<div class="panel mt-20">
			<div class="panel-body">
				<div class="clearfix">
					<span class="f-l"> <a href="javascript:;"
						onClick="location='?atcion=add';" class="btn btn-primary radius"><i
							class="Hui-iconfont">&#xe600;</i> 添加</a>
					</span>
				</div>
				<div class="clearfix mt-20">
					<table class="table table-striped table-bordered">
						<thead>
							<tr>
								<th>Id</th>
								<th>所属类别</th>
								<th>名称</th>
								<th>类型</th>
								<th>序号</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
<?php
    $rs1 = D("" . $db_pre . "options")->getLinkAll("id", true);
    $datas1 = $rs1['datas'];
    $rows1 = $rs1['rows'];
    If ($rows1 <= 0) {
        $OutStr = "<tr>";
        $OutStr = $OutStr . "<td colspan=10>&nbsp;<font color=\"red\">暂无内容</font></td>";
        $OutStr = $OutStr . "</tr></tbody>";
        echo $OutStr;
    } else {
        $pa = new \ZHMVC\B\TOOL\ShowPages();
        $pa->pvar = "pg";
        $pa->set(20, $rows1);
        $rs = D("" . $db_pre . "options")->where("classid<>'0'")
            ->order("id desc")
            ->limit($pa->limit())
            ->getLinkAll("*", true);
        $datas = $rs['datas'];
        $rows = $rs['rows'];
        // print_r($datas);
        for ($i = 0; $i < $rows; $i ++) {
            $data = $datas[$i];
            ?>
  <tr>
								<td><?php echo $data['id']; ?></td>
								<td><?php
                                    $bind1 = array(
                                        "id" => $data['classid']
                                    );
                                    $rs2 = D("" . $db_pre . "optionsclass")->where($bind1)->getLinkOne("*", true);
                                    $data2 = $rs2['datas'];
                                    $rows2 = $rs2['rows'];
                                    echo $data2['title'];
                                    $rs2=null;
                                    ?></td>
                                    
								<td><?php echo $data['title']; ?></td>
								<td><?php echo $data['type']; ?></td>
								<td><?php echo $data['paixu']; ?></td>
								<td class="taskOptions"><a
									href="?atcion=add&postid=<?php echo $data['id']; ?>">编辑</a> | <a
									href="?atcion=del&postid=<?php echo $data['id']; ?>"
									onclick="{if(confirm('确定删除吗?')){return true;}return false;}">删除</a></td>
							</tr>
<?php
        }
        ?>
    </tbody>
						<tfoot>
							<tr>
								<td colspan="10">&nbsp;<?php $pa -> output(0); ?></td>
							</tr>
						</tfoot>
<?php
    }
    ?>
</table>
				</div>
			</div>
		</div>
	</article>
<?php
}

function add($db_pre)
{
    $postid = SafeRequest(getPGC("postid"), 0);
    
    if (($postid != "") && ($postid != "0")) {
        $bind = array(
            "id" => $postid
        );
        $rs = D("" . $db_pre . "options")->where($bind)->getLinkOne("*", true);
        $data = $rs['datas'];
        $rows = $rs['rows'];
        If ($rows != 0) {
            $classid = $data['classid'];
            $title = $data['title'];
            $description = $data['description'];
            $type = $data['type'];
            $rules = $data['rules'];
            $rule = unserialize($rules);
            $formkey = $data['formkey'];
            $formvalue = $data['formvalue'];
            $otherkey = $data['otherkey'];
            $paixu =  $data['paixu'];
            
            if($formkey=="jzname" || $formkey=="jztel" || $formkey=="ername")
            {
                
            }
            else 
            {
                $formkey="other";
            }
            
            if ($type == "text") {
                $show_text = "none";
                $show_textarea = "none";
                $show_radio = "none";
                $show_checkbox = "none";
                $show_select = "none";
                $show_number = "none";
                $show_upload = "none";
                $show_etcode = "none";
                
                $rules_text = $rule['text'];
                $rules_radio = "";
                $rules_checkbox = "";
                $rules_select = "";
                $rules_number = "";
                $rules_upload = "";
                $rules_etcode = "";
            } elseif ($type == "textarea") {
                $show_text = "none";
                $show_textarea = "none";
                $show_radio = "none";
                $show_checkbox = "none";
                $show_select = "none";
                $show_number = "none";
                $show_upload = "none";
                $show_etcode = "none";
                
                $rules_text = "none";
                $rules_textarea = $rule['text'];
                $rules_radio = "";
                $rules_checkbox = "";
                $rules_select = "";
                $rules_number = "";
                $rules_upload = "";
                $rules_etcode = "";
            } elseif ($type == "etcode") {
                $show_text = "none";
                $show_textarea = "none";
                $show_radio = "none";
                $show_checkbox = "none";
                $show_select = "none";
                $show_number = "none";
                $show_upload = "none";
                $show_etcode = "none";
                
                $rules_text = "none";
                $rules_textarea = "";
                $rules_radio = "";
                $rules_checkbox = "";
                $rules_select = "";
                $rules_number = "";
                $rules_upload = "";
                $rules_etcode = $rule['text'];
            }elseif ($type == "radio") {
                $show_text = "none";
                $show_textarea = "none";
                $show_radio = "";
                $show_checkbox = "none";
                $show_select = "none";
                $show_number = "none";
                $show_upload = "none";
                $show_etcode = "none";
                $rules_radio = implode(PHP_EOL,$rule['text']);
                $rules_text = "";
                $rules_textarea = "";
                $rules_checkbox = "";
                $rules_select = "";
                $rules_number = "";
                $rules_upload = "";
                $rules_etcode = "";
            } elseif ($type == "checkbox") {
                $show_text = "none";
                $show_textarea = "none";
                $show_radio = "none";
                $show_checkbox = "";
                $show_select = "none";
                $show_number = "none";
                $show_upload = "none";
                $show_etcode = "none";
                $rules_checkbox = implode(PHP_EOL,$rule['text']);
                $rules_text = "";
                $rules_textarea = "";
                $rules_radio = "";
                
                $rules_select = "";
                $rules_number = "";
                $rules_upload = "";
                $rules_etcode = "";
            } elseif ($type == "select") {
                $show_text = "none";
                $show_textarea = "none";
                $show_radio = "none";
                $show_checkbox = "none";
                $show_select = "";
                $show_number = "none";
                $show_upload = "none";
                $show_etcode = "none";
                $rules_select = implode(PHP_EOL,$rule['text']);
                $rules_text = "";
                $rules_textarea = "";
                $rules_radio = "";
                $rules_checkbox = "";
                
                $rules_number = "";
                $rules_upload = "";
                $rules_etcode = "";
            } elseif ($type == "number") {
                $show_text = "none";
                $show_textarea = "none";
                $show_radio = "none";
                $show_checkbox = "none";
                $show_select = "none";
                $show_number = "none";
                $show_upload = "none";
                $show_etcode = "none";
                $rules_number = $rule['text'];
                $rules_text = "";
                $rules_textarea = "";
                $rules_radio = "";
                $rules_checkbox = "";
                $rules_select = "";
                $rules_upload = "";
                $rules_etcode = "";
            } elseif ($type == "upload") {
                $show_text = "none";
                $show_textarea = "none";
                $show_radio = "none";
                $show_checkbox = "none";
                $show_select = "none";
                $show_number = "none";
                $show_upload = "none";
                $show_etcode = "none";
                
                $rules_number = "";
                $rules_text = "";
                $rules_textarea = "";
                $rules_radio = "";
                $rules_checkbox = "";
                $rules_select = "";
                $rules_upload = $rule['text'];
                $rules_etcode = "";
            }
        } else {
            $show_text = "none";
            $show_textarea = "none";
            $show_radio = "none";
            $show_checkbox = "none";
            $show_select = "none";
            $show_number = "none";
            $show_upload = "none";
            $show_etcode = "none";
            
            $classid = '';
            $title = '';
            $description = '';
            $type = '';
            $formkey =  '';
            $formvalue =  '';
            $otherkey =  '';
            $paixu =  0;
            
            $rules_text = "";
            $rules_textarea = "";
            $rules_radio = "";
            $rules_checkbox = "";
            $rules_select = "";
            $rules_number = "";
            $rules_upload = "";
            $rules_etcode = "";
        }
    } else {
        $show_text = "none";
        $show_textarea = "none";
        $show_radio = "none";
        $show_checkbox = "none";
        $show_select = "none";
        $show_number = "none";
        $show_upload = "none";
        $show_etcode = "none";
        
        $classid = '';
        $title = '';
        $description = '';
        $type = '';
        $formkey =  '';
        $formvalue =  '';
        $otherkey =  '';
        $paixu =  0;
        
        $rules_text = "";
        $rules_textarea = "";
        $rules_radio = "";
        $rules_checkbox = "";
        $rules_select = "";
        $rules_number = "";
        $rules_upload = "";
        $rules_etcode = "";
    }
    
    ?>
<div class="panel">
<div class="Huialert Huialert-error"><i class="Hui-iconfont">&#xe6a6;</i>选择儿童身份证同时会生成性别和出生日期，其他身份证请使用字符串</div>
		<div class="panel-body">
			<form action="?atcion=save&id=<?php echo $postid; ?>" id="form1"
				name="form1" method="post" class="form form-horizontal">
				<!-- 表单 -->
				<div class="row clearfix">
					<label class="form-label col-xs-4 col-sm-3">所属分类：</label>
					<div class="form-controls col-xs-8 col-sm-9">
						<span class="select-box" style="width: 150px;"> <select
							id="classid" name="classid" class="select" size="1">
                                    <?php
    $rs2 = D("" . $db_pre . "optionsclass")->getLinkAll("`id`,`title`", true);
    $datas2 = $rs2['datas'];
    $rows2 = $rs2['rows'];
    for ($i = 0; $i < $rows2; $i ++) {
        $data2 = $datas2[$i];
        ?>
                                    <option
									value="<?php echo $data2['id'];?>"
									<?php
        If (empty($classid) == false) {
            If ($classid == $data2['id']) {
                echo " selected";
            }
        }
        ?>><?php echo $data2['title'];?></option>
                                    <?php
    }
    ?>
                                    </select>
						</span>
					</div>
				</div>

				<div class="row clearfix">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>名称：</label>
					<div class="form-controls col-xs-8 col-sm-9">
						<input type="text" name="title" class="input-text" placeholder=""
							value="<?php echo $title; ?>" />
					</div>
				</div>
				<div class="row clearfix">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>描述：</label>
					<div class="form-controls col-xs-8 col-sm-9">
						<input type="text" name="description" class="input-text"
							placeholder="" value="<?php echo $description; ?>" />
					</div>
				</div>
				<div class="row clearfix">
					<label class="form-label col-xs-12 col-sm-12"><span class="c-red"></span>注：宝宝姓名，家长姓名，家长电话请直接选择，其他的请选择其他，然后填写在文本框中</label>
				</div>
				<div class="row clearfix">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>表单中的名称：</label>
					<div class="form-controls col-xs-8 col-sm-9">
						<span class="select-box" style="width: 150px;"> <select
							id="formkey_id" name="formkey" class="select" size="1">
								<option value="ername" 
								<?php if($formkey == "ername") echo "selected"?>>宝宝姓名</option>
								<option value="jzname"
								<?php if($formkey == "jzname") echo "selected"?>>家长姓名</option>
								<option value="jztel"
								<?php if($formkey == "jztel") echo "selected"?>>家长电话</option>
								<option value="other"
								<?php if($formkey == "other") echo "selected"?>>其他名称</option>
						</select>
						</span>
						<input type="text" id="formvalue_other" name="formvalue_other" class="input-text"
							placeholder="" value="<?php echo $otherkey; ?>" />
					</div>
				</div>
				<div class="row clearfix">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>表单中的默认值：</label>
					<div class="form-controls col-xs-8 col-sm-9">
						<input type="text" name="formvalue" class="input-text"
							placeholder="" value="<?php echo $formvalue; ?>" />
					</div>
				</div>
				<div class="row clearfix">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>类型：</label>
					<div class="form-controls col-xs-8 col-sm-9">
						<span class="select-box" style="width: 150px;"> <select
							id="select_id" name="type" class="select" size="1">
								<option value="text" <?php if($type == "text") echo "selected"?>>字符串(text)</option>
								<option value="textarea"
									<?php if($type == "textarea") echo "selected"?>>编辑框(textarea)</option>
								<option value="number"
									<?php if($type == "number") echo "selected"?>>数字(number)</option>
								<option value="radio"
									<?php if($type == "radio") echo "selected"?>>单选(radio)</option>
								<option value="checkbox"
									<?php if($type == "checkbox") echo "selected"?>>多选(checkbox)</option>
								<option value="select"
									<?php if($type == "select") echo "selected"?>>选择(select)</option>
								<option value="upload"
									<?php if($type == "upload") echo "selected"?>>上传(upload)</option>
								<option value="etcode"
									<?php if($type == "etcode") echo "selected"?>>儿童身份证(etcode)</option>
						</select>
						</span>
					</div>
				</div>
				<div id="style_text" style="display:<?php echo $show_text;?>">
					<div class="row clearfix">
						<label class="form-label col-xs-4 col-sm-3">字符串(text)：</label>
						<div class="form-controls col-xs-8 col-sm-9">
							<input type="text" name="rules_text" class="input-text"
								placeholder="" value="<?php echo $rules_text; ?>" />
						</div>
					</div>
				</div>
				
				
				<div id="style_etcode" style="display:<?php echo $show_etcode;?>">
					<div class="row clearfix">
						<label class="form-label col-xs-4 col-sm-3">字符串(text)：</label>
						<div class="form-controls col-xs-8 col-sm-9">
							<input type="text" name="rules_etcode" class="input-text"
								placeholder="" value="<?php echo $rules_etcode; ?>" />
						</div>
					</div>
				</div>

				<div id="style_textarea" style="display:<?php echo $show_textarea;?>">
					<div class="row clearfix">
						<label class="form-label col-xs-4 col-sm-3">编辑框(textarea)：</label>
						<div class="form-controls col-xs-8 col-sm-9">
							<textarea name="rules_textarea" class="textarea" rows="6"
								placeholder=""><?php echo $rules_textarea; ?></textarea>
						</div>
					</div>
				</div>

				<div id="style_radio" style="display:<?php echo $show_radio;?>">
					<div class="row clearfix">
						<label class="form-label col-xs-4 col-sm-3">单选(radio)：</label>
						<div class="form-controls col-xs-8 col-sm-9">
							<b>选项内容:</b><br />只在项目为可选时有效，每行一个选项，后面为内容，例如: <br /> <i>苹果<br />香蕉<br />没有水果
							</i><br />注意: 选项确定后请勿修改内容的对应关系，但仍可以新增选项。如需调换显示顺序，可以通过移动整行的前后位置来实现<br />
							<textarea rows="8" name="rules_radio" id="rules[radio][choices]"
								cols="50"><?php echo $rules_radio?></textarea>
						</div>
					</div>
				</div>

				<div id="style_checkbox" style="display:<?php echo $show_checkbox;?>">
					<div class="row clearfix">
						<label class="form-label col-xs-4 col-sm-3">多选(checkbox)：</label>
						<div class="form-controls col-xs-8 col-sm-9">
							<b>选项内容:</b><br />只在项目为可选时有效，每行一个选项，后面为内容，例如: <br /> <i>苹果<br />香蕉<br />菠萝
							</i><br />注意: 选项确定后请勿修改内容的对应关系，但仍可以新增选项。如需调换显示顺序，可以通过移动整行的前后位置来实现<br />
							<textarea rows="8" name="rules_checkbox"
								id="rules[checkbox][choices]" cols="50"><?php echo $rules_checkbox?></textarea>

						</div>
					</div>
				</div>

				<div id="style_select" style="display:<?php echo $show_select;?>">
					<div class="row clearfix">
						<label class="form-label col-xs-4 col-sm-3">选择(select)：</label>
						<div class="form-controls col-xs-8 col-sm-9">
							<b>选项内容:</b><br />只在项目为可选时有效，每行一个选项，后面为内容，例如: <br /> <i>ZHMVC分类信息系统<br />ZHMVC企业建站系统<br />ZHMVC商务系统
							</i><br /> <br />注意:
							选项确定后请勿修改内容的对应关系，但仍可以新增选项。如需调换显示顺序，可以通过移动整行的前后位置来实现<br />
							<textarea rows="8" name="rules_select"
								id="rules[select][choices]" cols="50"><?php echo $rules_select?></textarea>


						</div>
					</div>
				</div>

				<div id="style_number" style="display:<?php echo $show_number;?>">
					<div class="row clearfix">
						<label class="form-label col-xs-4 col-sm-3">数字(number)：</label>
						<div class="form-controls col-xs-8 col-sm-9">
							<input type="text" size="50" name="rules_number"
								value="<?php echo $rules_number?>">
						</div>
					</div>
				</div>

				<div id="style_upload" style="display:<?php echo $show_upload;?>">
					<div class="row clearfix">
						<label class="form-label col-xs-4 col-sm-3">上传(upload)：</label>
						<div class="form-controls col-xs-8 col-sm-9">
							<b>上传名称:</b><br /> <input type="file" size="50"
								name="rules_upload" value="<?php echo $rules_upload?>">
						</div>
					</div>
				</div>

				
				<div class="row clearfix">
        			<label class="form-label col-xs-4 col-sm-3">序号：</label>
        			<div class="form-controls col-xs-8 col-sm-9">
        				<input type="text" name="paixu" class="input-text" placeholder=""
        							value="<?php echo $paixu; ?>" /><br>
        							序号越大越靠前，倒序
        			</div>
        		</div>
				<div class="row clearfix">
					<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
						<input class="btn btn-primary radius" type="submit"
							value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
					</div>
				</div>
			</form>
			<!-- 表单 -->
		</div>
	</div>
	<script type="text/javascript">

$("#select_id").change(function(){
	var styles, key;
	styles=new Array('text','textarea','radio','checkbox','select','number','upload','etcode');
	$('#style_'+styles[i]).css('display','none');
	console.log('2style_'+styles[i]);
	for(var i=0;i<styles.length;i++) {
		if(styles[i]==$("#select_id").val())
		{
			if($("#select_id").val()=="radio" || $("#select_id").val()=="checkbox" || $("#select_id").val()=="select" )
			{
				$('#style_'+$("#select_id").val()).css('display','');
				console.log('style_'+$("#select_id").val());
			}
			else
			{
				$('#style_'+styles[i]).css('display','none');
				console.log('2style_'+styles[i]);
			}
		}
		else
		{
			$('#style_'+styles[i]).css('display','none');
			console.log('2style_'+styles[i]);
		}
	}
});

$("#formkey_id").change(function(){

	if($("#formkey_id").val()=="other")
	{
		$("#formvalue_other").val('');
	}
	else
	{
		$("#formvalue_other").val($("#formkey_id").val())
	}
	
});
</script>
<?php
}

function save($db_pre)
{
    $postid = SafeRequest(getPGC("id"), 0);
    $classid = SafeRequest(getPGC("classid"), 0);
    $title = SafeRequest(getPGC("title"), 0);
    $description = SafeRequest(getPGC("description"), 0);
    $formkey = SafeRequest(getPGC("formkey"), 0);
    $formvalue = SafeRequest(getPGC("formvalue"), 0);
    $formvalue_other = SafeRequest(getPGC("formvalue_other"), 0);
    $paixu = SafeRequest(getPGC("paixu"), 0);
    
    $type = getPGC("type");
    
    // $rules=getPGC("rules_".$type);
    
    if ($type == "text") {
        $rules['text'] = getPGC("rules_" . $type);
        $rules['rule'] = 'maxlength';
        $rules['type'] = 'text';
    } elseif ($type == "etcode") {
        $rules['text'] = getPGC("rules_" . $type);
        $rules['rule'] = 'maxlength';
        $rules['type'] = 'textarea';
    }elseif ($type == "textarea") {
        $rules['text'] = getPGC("rules_" . $type);
        $rules['rule'] = 'maxlength';
        $rules['type'] = 'textarea';
    } elseif ($type == "radio") {
        $rules['text'] = explode(PHP_EOL, getPGC("rules_" . $type));
        $rules['rule'] = 'choices';
        $rules['type'] = 'radio';
    } elseif ($type == "checkbox") {
        $rules['text'] = explode(PHP_EOL, getPGC("rules_" . $type));
        $rules['rule'] = 'choices';
        $rules['type'] = 'checkbox';
    } elseif ($type == "select") {
        $rules['text'] = explode(PHP_EOL, getPGC("rules_" . $type));
        $rules['rule'] = 'choices';
        $rules['type'] = 'select';
    } elseif ($type == "number") {
        $rules['text'] = getPGC("rules_" . $type);
        $rules['rule'] = 'units';
        $rules['type'] = 'number';
    } elseif ($type == "upload") {
        $rules['text'] = getPGC("rules_" . $type);
        $rules['rule'] = 'units';
        $rules['type'] = 'upload';
    }
    
    $rule = serialize($rules);

    //var_dump($_POST);
    
    If ($formvalue_other == "") {
        $ErrMsg = "对不起，长度不符1！";
        $ErrMsg = $ErrMsg . "<li>长度等于0或大于250";
        echo $ErrMsg;
        exit();
    }
    else 
    {
        if($formkey=="other")
        {
            $formkey =$formvalue_other;
        }
    }
    
    If ($title == "") {
        $ErrMsg = "对不起，长度不符！";
        $ErrMsg = $ErrMsg . "<li>长度等于0或大于250";
        echo $ErrMsg;
        exit();
    }
    
    //判断键是否存在
    if (($postid != "") && ($postid != "0")) {
        $updatedata = array(
            "classid" => $classid,
            "title" => $title,
            "description" => $description,
            "type" => $type,
            "rules" => $rule,
            "formkey" => $formkey,
            "formvalue" => $formvalue,
            "otherkey" => $formvalue_other,
            "paixu" => $paixu
        );
        $wheremap = array(
            "id" => $postid
        );
        D("" . $db_pre . "options")->where($wheremap)->LinkUpdate($updatedata);
    } else {
        $rs=new \ZHMVC\D\Options();
        $data=$rs->getAll("formkey='".$formkey."'");
        $rows=$rs->getRows();
        if($rows>0)
        {
            $ErrMsg = "对不起，".$formkey."已经存在！";
            $ErrMsg = $ErrMsg . "<li>".$formkey."已经存在！";
            echo $ErrMsg;
            exit();
        }
        else 
        {
            if($type=="etcode")
            {
                
                $rs=new \ZHMVC\D\Options();
                $data=$rs->getAll("type='".$type."'");
                $rows=$rs->getRows();
                if($rows>0)
                {
                    $ErrMsg = "对不起，".$type."已经存在,并只能添加一次！";
                    $ErrMsg = $ErrMsg . "<li>".$type."已经存在,并只能添加一次！";
                    echo $ErrMsg;
                    exit();
                }
                else
                {
                    $IdWorker = \wantp\Snowflake\IdWorker::getIns();
                    $id = $IdWorker->id();
                    $updatedata = array(
                        "id" => $id,
                        "classid" => $classid,
                        "title" => $title,
                        "description" => $description,
                        "type" => $type,
                        "rules" => $rule,
                        "formkey" => 'gy_ersfz',
                        "formvalue" => $formvalue,
                        "otherkey" => $formvalue_other,
                        "paixu" => $paixu
                    );
                    D("" . $db_pre . "options")->LinkInsert($updatedata);
                    //宝宝性别
                    $IdWorker = \wantp\Snowflake\IdWorker::getIns();
                    $id = $IdWorker->id();
                    $updatedata = array(
                        "id" => $id,
                        "classid" => $classid,
                        "title" => '宝宝性别',
                        "description" => '请输入宝宝性别',
                        "type" => 'text',
                        "rules" => 'a:3:{s:4:\"text\";s:0:\"\";s:4:\"rule\";s:9:\"maxlength\";s:4:\"type\";s:4:\"text\";}',
                        "formkey" => 'gy_ersex',
                        "formvalue" => '',
                        "otherkey" => 'gy_ersex',
                        "paixu" => '0'
                    );
                    D("" . $db_pre . "options")->LinkInsert($updatedata);
                    //宝宝出生日期s
                    $IdWorker = \wantp\Snowflake\IdWorker::getIns();
                    $id = $IdWorker->id();
                    $updatedata = array(
                        "id" => $id,
                        "classid" => $classid,
                        "title" => '宝宝出生日期',
                        "description" => '请输入宝宝出生日期',
                        "type" => 'text',
                        "rules" => 'a:3:{s:4:\"text\";s:0:\"\";s:4:\"rule\";s:9:\"maxlength\";s:4:\"type\";s:4:\"text\";}',
                        "formkey" => 'gy_ercsrq',
                        "formvalue" => '',
                        "otherkey" => 'gy_ercsrq',
                        "paixu" => '0'
                    );
                    D("" . $db_pre . "options")->LinkInsert($updatedata);
                
                }
            }
            else 
            {
                $IdWorker = \wantp\Snowflake\IdWorker::getIns();
                $id = $IdWorker->id();
                $updatedata = array(
                    "id" => $id,
                    "classid" => $classid,
                    "title" => $title,
                    "description" => $description,
                    "type" => $type,
                    "rules" => $rule,
                    "formkey" => $formkey,
                    "formvalue" => $formvalue,
                    "otherkey" => $formvalue_other,
                    "paixu" => $paixu
                );
                D("" . $db_pre . "options")->LinkInsert($updatedata);
            }
        }
    }
    echo "<script>alert('更新成功');window.location.href='admin_options.php';</script>";
}

function del($db_pre)
{
    $postid = SafeRequest(getPGC("postid"), 0);
    
    if (($postid != "") && ($postid != "0")) {
        $wheremap = array(
            "id" => $postid
        );
        D("" . $db_pre . "options")->where($wheremap)->LinkDelete($wheremap);
        
        echo "<script>alert('更新成功');window.location.href='admin_options.php';</script>";
    }
}
?>
</div>
<?php
include (ZH_PATH . DS . MANAGERFPATH . DS . 'foot1' . ZH);
?>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>
